#!/bin/bash
# 0: 启动ES和调试环境
# 注意：es.sh 已经校验正确，保证依赖已经完整
:<<EOF
idea导入的方法
 直接打开elasticsearch目录，会识别到是gradle的工程，以这个打开即可
 工程默认有配置的运行配置“Debug Elasticsearch”,首先点击执行这个【这个会启动一个5005的默认监听服务】
EOF
read -p "Idea's Debug ElasticSearch is ready? [Listen on 5005], y to continue"
netstat -nat|grep :5005|grep LISTEN ||(
 echo "idea not start debuger"
 exit 1
)

#　不能root用户执行
pushd elasticsearch
 export JAVA_HOME=/opt/dev/jdk-14.0.1/;./gradlew run --debug-jvm --info --offline &
popd

echo "wait for es startup..."
sleep 60
while [ -z "`curl -fs http://172.17.0.1:9200/`" ]
do
  echo "wait es"
  sleep 3
done

echo "start kibana"
pushd kibana
 docker-compose up
popd

# elasticsearch终止
ps ax|grep "debug-jvm"| grep -v "grep" && (
 kill -9 $(ps ax|grep "debug-jvm"| grep -v "grep"| awk '{print $1}')
)


